<?php
/**
 * Created by PhpStorm.
 * User: angl
 * Date: 2016/9/28
 * Time: 19:19
 */
namespace AuctionCore\AntNest;

class UserCenter extends Client
{

    public function __construct()
    {
        $this->urlPath = 'ucenter/api/accounts/';
    }

    /**
     * 添加用户信息
     *
     * @param $data
     * @param $type
     *
     * @return mixed
     */
    public function add($data, $type)
    {
        $this->urlPath = $this->urlPath . "add";
        $this->params = [
            'account_type' => $type,
            'account_name' => $data['account_name'],
            'pwd' => $data['pwd'],
            'mobile' => $data['mobile'],
            'email' => $data['email'],
            'manager_account_id' => $data['emp_id'],
            'manager_ip' => $data['emp_ip']
        ];
        return $this->getData();
    }

    /**
     * 车来车往车主用户注册
     *
     * @param string $mobile
     * @param string $password
     * @param int    $accountType
     *
     * @return mixed
     */
    public function register($mobile, $password, $accountType = 1)
    {
        $this->params = [
            'account_type' => $accountType,
            'mobile' => $mobile,
            'pwd' => $password
        ];
        $this->urlPath = $this->urlPath . "regist";
        $this->isPost = 1;
        return $this->getData();
    }

    /**
     * 批量获取用户信息
     *
     * @param $type
     * @param $ids
     *
     * @return mixed
     */
    public function batchInfo($ids, $type)
    {
        $this->urlPath = $this->urlPath . "batchinfo";
        $this->params = [
            'account_type' => $type,
            'account_id' => $ids
        ];
        return $this->getData();
    }
    /**
     * 通过mobile获取用户信息
     *
     * @param $mobile
     * @param $account_type
     *
     * @return mixed
     */
    public function info_bymobile($mobile, $account_type,$isAjax=0)
    {
        $this->urlPath = $this->urlPath . "info";
        $this->is_post = 0;
        $this->params = [
            'account_type' => $account_type,
            'mobile' => $mobile
        ];
        return $this->getData();
    }
    /**
     * 通过id获取用户信息
     *
     * @param     $account_id
     * @param int $type
     * @param int $account_type
     *
     * @return mixed
     */

    public function info($account_id, $account_type = 1, $type = 1)
    {
        if ($type == 2) {
            $this->params = [
                'account_type' => $account_type,
                'mobile' => $account_id
            ];
        } else {
            $this->params = [
                'account_type' => $account_type,
                'account_id' => $account_id
            ];
        }
        $this->urlPath = $this->urlPath . "info";
        $this->is_post = 0;
//        $this->params = [
//            'account_type' => $account_type,
//            'account_id' => $account_id
//        ];
        return $this->getData();
    }

    public function getInfo($account_id, $account_type)
    {
        $this->urlPath = $this->urlPath . "info";
        $this->is_post = 0;
        $this->params = [
            'account_type' => $account_type,
            'account_id' => $account_id
        ];
        return $this->getData();
    }

    /**
     * 通过用户名获取用户信息
     *
     * @param $account_name
     * @param $account_type
     *
     * @return bool
     */
    public function infoByAccountName($account_name, $account_type)
    {
        $this->urlPath = $this->urlPath . "info";
        $this->is_post = 0;
        $this->params = [
            'account_type' => $account_type,
            'account_name' => $account_name
        ];
        return $this->getData();
    }

    /**
     * 通过用户id修改用户信息
     *
     * @param  array $user         用户信息
     * @param int    $account_type 用户类型
     *
     * @return mixed
     */
    public function changeUserInfo($user, $account_type)
    {
        $this->urlPath = $this->urlPath . "changeuserinfo";
        $this->params = array(
            'account_type' => $account_type,
            'account_id' => $user['account_id'],
            'mobile' => $user['mobile'],
            'manager_account_id' => $user['emp_id'],
            'manager_ip' => $user['emp_ip']
        );
        return $this->send();
    }

    /**
     * 启用用户帐号
     *
     * @param array $user
     * @param int   $account_type
     *
     * @return mixed
     */
    public function active($user, $account_type)
    {
        $this->urlPath = $this->urlPath . "active";
        $this->params = array(
            'account_type' => $account_type,
            'account_id' => $user['account_id'],
            'manager_account_id' => $user['emp_id'],
            'manager_ip' => $user['emp_ip']
        );
        return $this->send();
    }

    /**
     * 禁用用户帐号
     *
     * @param array $user
     * @param int   $account_type
     *
     * @return mixed
     */
    public function inactive($user, $account_type)
    {
        $this->urlPath = $this->urlPath . "inactive";
        $this->params = array(
            'account_type' => $account_type,
            'account_id' => $user['account_id'],
            'manager_account_id' => $user['emp_id'],
            'manager_ip' => $user['emp_ip']
        );
        return $this->send();
    }

    /**
     * 重置密码
     *
     * @param $user
     * @param $account_type
     *
     * @return mixed
     */
    public function resetpwd($user, $account_type)
    {
        $this->urlPath = $this->urlPath . "resetpwd";
        $this->params = array(
            'account_type' => $account_type,
            'account_id' => $user['account_id'],
            'pwd_new' => $user['pwd'],
            'manager_account_id' => $user['emp_id'],
            'manager_ip' => $user['emp_ip']
        );
        return $this->send();

    }
    public function get_repair_check_list($params){
        $this->urlPath = 'pub/api/searchReportLog';
        $this->is_post = 1;
        $this->params = $params;
        return $this->getData();
    }
}
